package com.hy.controller;

import com.hy.common.base.RespResult;
import com.hy.common.log.annotation.SysOpLogAnnotation;
import com.hy.entity.dto.DepartmentSearchDTO;
import com.hy.entity.dto.PropertyOneDTO;
import com.hy.entity.dto.PropertyUserChangeDTO;
import com.hy.service.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/public")
public class PublicController {


    @Resource
    private HyDepartmentService hyDepartmentService;

    @Resource
    private  HyUnitService  hyUnitService;
    @Resource
    private HyPropertyRecordService recordService;

    @Resource
    private HyPropertyService propertyService;
    @Resource
    private SysUserService userService;
    @Resource
    private HyPlaceService placeService;
    @Resource
    private HyPropertySortService sortService;
    @RequestMapping("/getCanHandleDepartmentList")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "查看可操作的部门",reqParam ="'请求了部门'")
    public RespResult getCanHandleDepartmentList(){

       return hyDepartmentService.getCanHandleDept();


    }

    @RequestMapping("/getCanWatchUnit")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "查看可操作的单位",reqParam ="'请求了单位'")
    public RespResult getCanWatchUnit(){

        return  hyUnitService.getCanHandleUnit();
    }


    @RequestMapping("/applyChange")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "发起资产变更",reqParam ="'变更后使用人：'+#dto.ownerId")
    public RespResult applyChange(@RequestBody PropertyUserChangeDTO dto){



        return propertyService.changeUser(dto);

    }

    @RequestMapping("/getCheckRecord")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "查看我的资产变更记录",reqParam = "'查看'")
    public RespResult getCheckRecord(){



        return recordService.showMyChangeApply();

    }


    @GetMapping("/getUnitTree")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "获取单元树",reqParam = "'获取单元树'")
    public RespResult getUnitTree(){

        return propertyService.getUnitTree();

    }




    @GetMapping("/getPropertyByUserId")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "查看我的资产",reqParam = "'查看'")
    public RespResult getPropertyByUserId(PropertyOneDTO userId){

        return propertyService.getPropertyByUserId(userId);

    }
    @GetMapping("/getPropertyById")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "按照资产ID查看资产",reqParam = "'查看'")
    public RespResult getPropertyById(Integer id){


        return propertyService.getPropertyByPropertyId(id);
    }
    @GetMapping("/listUsersByDept")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "根据部门获取人员信息",reqParam = "'查看'")
    public RespResult listUsersByDept(Integer deptId){
        return userService.getUserByDept(deptId);
    }

    @GetMapping("/getTree")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "获取区域树",reqParam = "'无'")
    public RespResult getTree(){
        return placeService.getPlaceTree();

    }



    @GetMapping("/getPropertySortTree")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "获取资产树",reqParam = "'无'")
    public RespResult getPropertySortTree(){
        return sortService.showTreeSort();

    }
    @GetMapping("/propertyHistoryUser")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "获取当前资产使用人及历史使用人",reqParam = "'无'")
    public RespResult propertyHistoryUser(Integer id){
        return recordService.propertyHistoryUser(id);

    }

    @GetMapping("/getOutUser")
    @SysOpLogAnnotation(menuName = "公共",menuBtn = "获取当前资产使用人及历史使用人",reqParam = "'无'")
    public RespResult getOutUser(){
        return userService.getOutUserTree();

    }
}
